﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;
using PumpDisplay.PetroFexPumpServiceReference;

namespace PumpDisplay
{
    /// <summary>
    /// Interaction logic for PumpIDInputWindow.xaml
    /// </summary>
    public partial class PumpIDInputWindow : Window
    {
        PetroFexServiceClient client = new PetroFexServiceClient();
        public PumpIDInputWindow()
        {
            InitializeComponent();
        }

        private void startPumpBtn_Click(object sender, RoutedEventArgs e)
        {
            List<PetrolPump> pumps = new List<PetrolPump>();
            try
            {
	            pumps = client.getPumps();
            }
            catch (SystemException ex)
            {
                MessageBox.Show("FATAL ERROR: The server is not active! Cannot connect pump.", "Fatal Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
	            bool existspump = pumps.Exists(pump => pump.PumpId == pumpIdBox.Text);
	            if (!existspump) //if pump doesnt exist
	            {
	                var pumpWindow = new PumpWindow(pumpIdBox.Text);
	                pumpWindow.Show();
	                this.Close();
	            }
	            else
	                MessageBox.Show("This Pump Is Already Active!", "Invalid Pump Specified", MessageBoxButton.OK, MessageBoxImage.Error);
        }
    }
}
